package com.example.demo.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import lombok.Data;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * dishes
 * @author 
 */
@Data
@Component
public class Dishes implements Serializable {
    private Long dishId;

    private String name;

    private List<Ingredients> DIngredients;

    private Nutritionalvalue nutritionalvalue;

    private String creators;

    private String description;

    private String image;

    private Integer viewCount;

    private static final long serialVersionUID = 1L;

    public Dishes(Long dishId, String name) {
        this.dishId = dishId;
        this.name = name;
    }

    @PostConstruct
    public void init() {
        if (this.name != null) {
            this.DIngredients = getIngredientsByDishName(this.name);
        }
    }

    public Dishes(String dishName, List<Ingredients> ingredientList, String base64Image) {
    }

    public Dishes(String name, String description, String imageUrl) {
        this.name = name;
        this.description = description;
        this.image = imageUrl;
    }

    public Dishes() {

    }

    public void increaseViews() {
        this.viewCount++;
    }

    public List<Ingredients> getIngredientsByDishName(String dishName) {
        List<Ingredients> ingredientsList = new ArrayList<>();

        // 判断菜品名称中是否包含关键词，然后创建相应的食材对象并添加到链表中
        if (dishName.contains("排骨") || dishName.contains("肉")) {
            Ingredients pork = new Ingredients();
            pork.setName("猪肉");
            ingredientsList.add(pork);
        }

        if (dishName.contains("鸡") || dishName.contains("鸭") || dishName.contains("鱼")) {
            Ingredients poultry = new Ingredients();
            poultry.setName("禽肉");
            ingredientsList.add(poultry);
        }

        return ingredientsList;
    }

}